<?php 
namespace Admin\Controller;
use Think\Controller;
class SortsController extends Controller{
	
		protected $db;
		protected function _initialize(){
			$this->db = D('Sorts');
		}
		
		public function index(){
			$list = $this->db->getAll();
			$this->assign('list',$list);
			$this->display();
		}
		
		public function add(){
			if(IS_POST){
				if($this->db->m_add()){
					$this->success('添加成功','index');
				}else{
					$this->error($this->db->getError());
				}
			}else{
				$this->display();
			}
			
		}
		
		public function edit(){
			if(IS_POST){
				if($this->db->edit()){
					$this->success('修改成功','index');
				}else{
					if(empty($this->db->getError())){
						$this->error('修改失败，值相同');
					}else{
						$this->error($this->db->getError());
					}
					
				}
			}else{
				$data = $this->db->getAll(I('GET.id'));
				$this->assign('data',$data);
				$this->display();
			}
		}
		
		public function del(){
			if(IS_GET){
				if($this->db->del()){
					$this->success('删除成功');
				}else{
					$this->error('删除失败');
				}
			}
		}
		
		
}